import { getToken, request } from '@inbiz/utils';

const token = getToken();
// 获取流程按钮权限
export async function getPermissions(params?: any) {
  return request(
    `/edoc2Flow-web/edoc-task/${params.taskId}/getActivityInfo?taskId=${params.taskId}&orgToken=${token}`,
    {
      method: 'get',
      headers: {
        vVersion: 'v6',
      },
    },
  );
}

/*
发起申请
'processDefinitionId':'', 流程解析KEY
'starter':'', 发起人ID
'variablesParams ': [{"name":"num","value":"2"}],
'signDataStr':'', 电子签名
'businessKey':''  表单提交id
*/
export async function startProcess(params?: any) {
  return request(`/edoc2Flow-web/process/commonly/startProcessInstance?orgToken=${token}`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

/*
退回上一步
taskId: '' 任务ID
rejectOrgin: '' 审批意见
*/
export async function returnBack(params?: any) {
  return request(`/edoc2Flow-web/process/commonly/rejectPrevActivity?orgToken=${token}`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

/*
退回发起人
taskId: ''
rejectOrgin: ''
backReturn: true false
*/
export async function returnStarter(params?: any) {
  return request(`/edoc2Flow-web/process/commonly/rejectStarterActivity?orgToken=${token}`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

/*
终止流程
id: '' 流程实例号 
taskId: '' 任务ID
comment: '' 审批意见 
*/
export async function cancelProcess(params?: any) {
  return request(`/edoc2Flow-web/process/commonly/stopProcessInstance?orgToken=${token}`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

/*
保存到草稿箱
starer: '' 发起人ID
procDefId: '' 流程定义ID，实例：’process9963a6a6ebf246c7a4bbfb9e4ff7e792:1:15004‘
*/
export async function saveDraft(params?: any) {
  return request(`/edoc2Flow-web/process/external/depositDraft?orgToken=${token}`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

/*
加签
taskId: '' 任务ID
plusSignType: '' skipCurrent：前加签；skipNext:后加签
commonet: '' 审批意见
assigenLists: '' 被加签人ID（多人使用逗号隔开）
*/
export async function plusSign(params?: any) {
  return request(`/edoc2Flow-web/process/commonly/plusSign?orgToken=${token}`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

/**
 * 同意
 *  taskId
 * comment
 *  variablesParams
 */

export async function approval(params?: any) {
  return request(`/edoc2Flow-web/process/commonly/completeTask?orgToken=${token}`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 获取变量信息
export async function getVariables(params) {
  return request(`/edoc2Flow-web/edoc-etc-processManage/getMobileVars?orgToken=${token}`, {
    method: 'get',
    params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 撤回
export async function withDrawProcess(params?: any) {
  return request(`/edoc2Flow-web/process/commonly/processWithdraw?orgToken=${token}`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 抄送
export async function sendTo(params?: any) {
  return request(`/edoc2Flow-web/process/commonly/saveProcessCC?orgToken=${token}`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 退回发起人后的提交
export async function submitTask(params?: any) {
  return request(`/edoc2Flow-web/process/commonly/completeTask?orgToken=${token}`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 催办
export async function doItFast(params?: any) {
  return request(`/edoc2Flow-web/process/operation/processUrging`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}

// 指派
export async function assignTask(params: any) {
  return request(`/edoc2Flow-web/process/operation/processAssignment`, {
    method: 'post',
    data: params,
    headers: {
      vVersion: 'v6',
    },
  });
}